class User(object):
    def __init__(self, name, age):
        self._name = name  # _ 表示受保护的变量
        self.__age = age  # __ 表示私有变量

    # def get_age(self):
    #     return self.__age
    #
    # def set_age(self, age):
    #     if isinstance(age, int):
    #         self.__age = age
    #     else:
    #         raise Exception('年龄只能是整数')

    @property
    def name(self):
        return self._name

    @property
    def age(self):
        return self.__age

    @age.setter
    def age(self, age):
        if isinstance(age, int):
            self.__age = age
        else:
            raise Exception('年龄只能是整数')


jack = User('jack', 18)
# print(jack._name)
# print(jack.__age)
# print(jack.__dict__)
# print(jack._User__age)
# print(jack.get_age())

# try:
#     jack.set_age('二十五')
# except:
#     print("年龄只能是整数")


print(jack.name)
print(jack.age)
jack.age = 20
print(jack.age)

